import Router from './director.js';
import Reg from '../pages/reg.js';
import Login from '../pages/login.js';
import Manage from '../pages/manage.js';
import Student from '../pages/student.js';
import Cls from '../pages/class.js';
const {$} = layui;
let routes = {
    '/reg':() => new Reg(),
    '/login':() => new Login(),
    '/manage':{
        '/student': () => new Student(),
        '/class': () => new Cls(),
        on:(next) => new Manage(next)
    }
};

// 设置ajax的全局属性，用于提交token信息
$.ajaxSettings.beforeSend = function(xhr){
     // 在这里加上你的 token 
     xhr.setRequestHeader('Authorization','Bearer ' + localStorage.token);
}
$.ajaxSettings.error = function(err){
    if(err.status == 401){
        location.href = "#login";
    }
}

// 默认访问登录模块
location.hash = location.hash || "#login";
let router = Router(routes).configure({
    recurse: 'forward', // 递归匹配forward、backword、false
    async:true,
    strict:false
}); // 实例化路由
router.init(); // 初始化路由